package com.deuwise.common.utils;

import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Copyright
 *
 * @Author:chenwenchao
 * @Date:2018/4/19 Description:
 */
public class TypeUtil {

    /**
     * 判断字符串是否是Integer类型
     * @param input
     * @return
     */
    private  static  Pattern NUMBER_PARTERN=Pattern.compile("^[+-]?[0-9]+$");
    public static boolean isInteger(String input){
        Matcher mer = NUMBER_PARTERN.matcher(input);
        return mer.find();
    }
    /**
     * 队列比较
     * @param <T>
     * @param a
     * @param b
     * @return
     */
    public static <T extends Comparable<T>> boolean compare(List<T> a, List<T> b) {
        if(a.size() != b.size()) {
            return false;
        }
        Collections.sort(a);
        Collections.sort(b);
        for(int i=0;i<a.size();i++){
            if(!a.get(i).equals(b.get(i))) {
                return false;
            }
        }
        return true;
    }
    /**
     * 功能：判断字符串是否为日期格式
     *
     * @param str
     * @return
     */
    private  static  Pattern MOBILE_PARTERN=Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
    public static boolean isDate(String strDate) {
        Matcher m = MOBILE_PARTERN.matcher(strDate);
        if (m.matches()) {
            return true;
        } else {
            return false;
        }
    }
}
